income[incgroup_prepost_x=="26. $150,000-$174,999"] <-162500
income[incgroup_prepost_x=="27. $175,000-$249,999"] <- 212500
income[incgroup_prepost_x=="28. $250,000 or more"] <- 250000
# ANES Region
region <- NA
region[sample_region=="1. Northeast"] <- 1
region[sample_region=="2. North central"] <- 2
region[sample_region=="3. South"] <- 3
region[sample_region=="4. West"] <- 4
region_northeast <- NA
region_northeast[region==1] <- 1
region_northeast[region!=1] <- 0
region_midwest <- NA
region_midwest[region==2] <- 1
region_midwest[region!=2] <- 0
region_south <- NA
region_south[region==3] <- 1
region_south[region!=3] <- 0
region_west <- NA
region_west[region==4] <- 1
region_west[region!=4] <- 0
### ANES Political Opinions
# ANES 7 Point Party ID
party7 <- NA
party7[pid_self=="1. Democrat" & pid_strong=="1. Strong"] <- 1
party7[pid_self=="1. Democrat" & pid_strong=="2. Not very strong"] <- 2
party7[pid_lean=="3. Closer to Democratic"] <- 3
party7[pid_lean=="2. Neither {VOL}"] <- 4
party7[pid_lean=="1. Closer to Republican"] <- 5
party7[pid_self=="2. Republican" & pid_strong=="1. Strong"] <- 6
party7[pid_self=="2. Republican" & pid_strong=="2. Not very strong"] <- 7
seniors <- NA
healthcare <- NA
immigration <- NA
gaymarriage <- NA
taxrich <- NA
taxpoor <- NA
# ANES Voter Registration
register <- NA
register[prevote_regist_addr=="1. Registered at this address"|prevote_regist_addr=="2. Registered at a different address"] <- 1
register[prevote_regist_addr=="3. Not currently registered"] <- 0
# ANES Voting
vote <- NA
vote[rvote2012_x==1] <- 1
vote[rvote2012_x==2] <- 0
vote[rvote2012_x==-2] <- NA
vote[rvote2012_x==-6] <- NA
#Politcal Knowledge
knowl_succession <- NA
knowl_override <- NA
knowl_pres <- NA
knowl_senterm <- NA
knowl_numsen <- NA
knowl_houseterm <- NA
knowl_score <- NA
extraverted  <- as.numeric(tipi_extra)-4
extraverted[tipi_extra=="-9. Refused"|tipi_extra=="-8. Don't know"|tipi_extra=="-7. Deleted due to partial (post-election) interview"|tipi_extra=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
reserved     <- 7-(as.numeric(tipi_resv)-5)
reserved[tipi_resv=="-9. Refused"|tipi_resv=="-8. Don't know"|tipi_resv=="-7. Deleted due to partial (post-election) interview"|tipi_resv=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
extraversion <- (extraverted + reserved)/2
critical      <- 7-(as.numeric(tipi_crit)-5)
critical[tipi_crit=="-9. Refused"|tipi_crit=="-8. Don't know"|tipi_crit=="-7. Deleted due to partial (post-election) interview"|tipi_crit=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
sympathetic   <- as.numeric(tipi_warm)-4
sympathetic[tipi_warm=="-9. Refused"|tipi_warm=="-8. Don't know"|tipi_warm=="-7. Deleted due to partial (post-election) interview"|tipi_warm=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
agreeableness <- (critical + sympathetic)/2
dependable        <- as.numeric(tipi_dep)-4
dependable[tipi_dep=="-9. Refused"|tipi_dep=="-8. Don't know"|tipi_dep=="-7. Deleted due to partial (post-election) interview"|tipi_dep=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
disorganized      <- 7-(as.numeric(tipi_disorg)-5)
disorganized[tipi_disorg=="-9. Refused"|tipi_disorg=="-8. Don't know"|tipi_disorg=="-7. Deleted due to partial (post-election) interview"|tipi_disorg=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
conscientiousness <- (dependable + disorganized)/2
anxious            <- 7-(as.numeric(tipi_anx)-5)
anxious[tipi_anx=="-9. Refused"|tipi_anx=="-8. Don't know"|tipi_anx=="-7. Deleted due to partial (post-election) interview"|tipi_anx=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
calm               <- as.numeric(tipi_calm)-4
calm[tipi_calm=="-9. Refused"|tipi_calm=="-8. Don't know"|tipi_calm=="-7. Deleted due to partial (post-election) interview"|tipi_calm=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
emotionalstability <- (anxious + calm)/2
open                  <- as.numeric(tipi_open)-4
open[tipi_open=="-9. Refused"|tipi_open=="-8. Don't know"|tipi_open=="-7. Deleted due to partial (post-election) interview"|tipi_open=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
conventional          <- 7-(as.numeric(tipi_conv)-5)
conventional[tipi_conv=="-9. Refused"|tipi_conv=="-8. Don't know"|tipi_conv=="-7. Deleted due to partial (post-election) interview"|tipi_conv=="-6. Not asked, unit nonresponse (no post-election interview)"]  <- NA
opennesstoexperiences <- (conventional + open)/2
extraversion <- (extraversion-1)/6
agreeableness <- (agreeableness-1)/6
conscientiousness <- (conscientiousness-1)/6
emotionalstability <- (emotionalstability-1)/6
opennesstoexperiences <- (opennesstoexperiences-1)/6
ramean <- NA
NFC <- NA
NTE <- NA
weights <- weight_ftf
survey <- "anes2012"
})
# Save Datasets -----------------------------------------------------------
# Clean Files
save(anes, file = "drafts/ResearchPolitics/anes_cleaned.rdata")
save(anes2012, file = "drafts/ResearchPolitics/anes2012_cleaned.rdata")
weighted.mean(anes$NFC, w=anes$weights, na.rm = TRUE)
# Master Cleaning file
# Replication of Berinsky, Huber, and Lenz (2012)
rm(list=ls())
#setwd("~/Documents/Dropbox/Columbia/Collaboration/Work for Don/Lucid Validation/")
setwd("~/Dropbox/Lucid Validation/")
library(dplyr)
library(foreign)
library(devtools)
library(stringr)
source("programs/Lucid_Validation_Helper_Functions.R")
load("drafts/ResearchPolitics/anes_cleaned.rdata")
load("drafts/ResearchPolitics/anes2012_cleaned.rdata")
load("drafts/ResearchPolitics/anes_panel_cleaned.rdata")
load("data/clean_data/cces_cleaned.rdata")
load("data/clean_data/ccap_cleaned.rdata")
load("data/clean_data/cps_and_cps_income_cleaned.rdata")
load("data/clean_data/GSS_cleaned.rdata")
load("data/clean_data/Kam_Simas_cleaned.rdata")
load("data/clean_data/lucid_cleaned.rdata")
load("data/clean_data/berinksy_mturk_1_cleaned.rdata")
load("data/clean_data/MTurk_Kam_merge_cleaned.rdata")
load("data/clean_data/mturk_AD.rdata")
load("data/clean_data/mturk_rumor.rdata")
load("data/clean_data/mturk_risk_cleaned.rdata")
load("data/clean_data/original_AD.rdata")
load("data/clean_data/ssi_rumor.rdata")
load("data/clean_data/Survey_Behavior_Table_Cleaned.rdata")
# Stacked Datasets --------------------------------------------------------
# Demos
anes_trim <- select(anes, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
anes2012_trim <- select(anes2012, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
anes_panel_trim <- select(anes_panel, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
cps_trim <- select(cps, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
cps_income_trim <- select(cps_income, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
mturk_trim <- select(mturk, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
lucid_trim <- select(lucid_combined, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, weights, survey)
demos_stacked <- rbind(anes_trim, anes2012_trim, anes_panel_trim, cps_trim, cps_income_trim, mturk_trim, lucid_trim)
# Political
lucid_trim3 <- select(lucid_combined, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
mturk_trim3 <- select(mturk, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
anes_panel_trim3 <- select(anes_panel, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
cps_trim3 <- select(cps, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
anes_trim3 <- select(anes, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
anes2012_trim3 <- select(anes2012, register, vote, party7, ideology, interest, knowl_score, seniors, healthcare, immigration, gaymarriage, taxrich, taxpoor, weights, survey)
politics_stacked <- rbind(lucid_trim3, mturk_trim3, anes_panel_trim3, cps_trim3, anes_trim3, anes2012_trim3)
# Psychological
lucid_trim4 <- select(lucid_combined, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
mturk_trim4 <- select(mturk, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
mturk_risk_trim4 <- select(mturk_risk, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
kam_trim4 <- select(kam, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
anes_panel_trim4 <- select(anes_panel, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
anes_trim4 <- select(anes, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
anes2012_trim4 <- select(anes2012, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
cces_trim4 <- select(cces, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
ccap_trim4 <- select(ccap, NFC, NTE, ramean, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
psych_stacked <- rbind(lucid_trim4, mturk_trim4, mturk_risk_trim4, kam_trim4, anes_panel_trim4, anes_trim4, anes2012_trim4, cces_trim4, ccap_trim4)
# Standardized Scores Stacked
lucid_trim5 <- select(lucid_combined, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, register, vote, party7, ideology, interest, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
mturk_trim5 <- select(mturk, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, register, vote, party7, ideology, interest, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
mturk_risk_trim5 <- select(mturk_risk, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, register, vote, party7, ideology, interest, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
anes2012_trim5 <- select(anes2012, female, education, age, income, race_white, race_black, race_hispanic, race_asian, race_native, region_northeast, region_midwest, region_south, region_west, register, vote, party7, ideology, interest, extraversion,agreeableness,conscientiousness,emotionalstability,opennesstoexperiences, weights, survey)
standardized_stacked <- rbind(lucid_trim5, mturk_trim5, mturk_risk_trim5, anes2012_trim5)
save(demos_stacked, file = "drafts/ResearchPolitics/ReplicationArchive/Demos_Table_Stacked_Cleaned.rdata")
save(politics_stacked, file = "drafts/ResearchPolitics/ReplicationArchive/Politics_Table_Stacked_Cleaned.rdata")
save(psych_stacked, file = "drafts/ResearchPolitics/ReplicationArchive/Psych_Table_Stacked_Cleaned.rdata")
save(standardized_stacked, file = "drafts/ResearchPolitics/ReplicationArchive/Standardized_Table_Cleaned.rdata")
means <-
psych_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.mean(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "mean")
ses <-
psych_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.se(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "se")
means <- within(means,{
mean[variable=="NFC" & survey=="mturk"] <- mean[variable=="NFC" & survey=="mturk_risk"]
mean[variable=="NTE" & survey=="mturk"] <- mean[variable=="NTE" & survey=="mturk_risk"]
mean[variable=="ramean" & survey=="mturk"] <- mean[variable=="ramean" & survey=="mturk_risk"]
})
ses <- within(ses,{
se[variable=="NFC" & survey=="mturk"] <- se[variable=="NFC" & survey=="mturk_risk"]
se[variable=="NTE" & survey=="mturk"] <- se[variable=="NTE" & survey=="mturk_risk"]
se[variable=="ramean" & survey=="mturk"] <- se[variable=="ramean" & survey=="mturk_risk"]
})
means_and_ses <- left_join(means, ses) %>%
filter(variable != "weights", survey!="mturk_risk")
means_and_ses <- within(means_and_ses,{
entry <- rep(NA, nrow(means_and_ses))
entry <-
paste0(format_num(mean, digits = 2), " ",
add_parens(se, digits = 2))
})
Ns <-
psych_stacked %>%
filter(survey!="mturk_risk")%>%
group_by(survey) %>%
summarize(n = n(),
n = comma_format()(n)) %>%
melt(id.var = "survey", value.name = "entry")
df <- bind_rows(means_and_ses %>% select(survey, variable, entry),
Ns)
psych_table <- df %>% dcast(variable ~ survey, value.var = "entry") %>%
bind_rows(data.frame(variable = "Big 5 Personality Index"))
psych_table <- within(psych_table,{
anes[anes == "NA (NA)"] <- ""
anes_panel[anes_panel == "NA (NA)"] <- ""
anes2012[anes2012 == "NA (NA)"] <- ""
anes2012[anes2012 == "NaN (NaN)"] <- ""
cces[cces == "NA (NA)"] <- ""
cces[cces == "NaN (NaN)"] <- ""
ccap[ccap == "NA (NA)"] <- ""
ccap[ccap == "NaN (NaN)"] <- ""
kam[kam == "NaN (NaN)"] <- ""
variable <- factor(variable, levels = c("Big 5 Personality Index","agreeableness","conscientiousness",
"emotionalstability","extraversion", "opennesstoexperiences", "ramean", "NFC",
"NTE", "n"))
})
psych_table <-
psych_table[,c("variable", "lucid", "mturk", "cces", "ccap", "anes_panel", "anes", "anes2012","kam" )] %>%
arrange(variable)
View(psych_table)
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/DemosTableStacked.rdata")
rm(list=ls())
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/DemosTableStacked.rdata")
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/StandardizedDemos.rdata")
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/Standardized_Table_Cleaned.rdata")
View(standardized_stacked)
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/StandardizedDemos.rdata")
View(standardized_stacked)
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/Standardized_Table_Cleaned.rdata")
rm(list=ls())
load("/Users/Ollie/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive/Standardized_Table_Cleaned.rdata")
View(standardized_stacked)
rm(list=ls())
setwd("~/Dropbox/Lucid Validation/drafts/ResearchPolitics/ReplicationArchive")
library(dplyr)
library(stargazer)
source("LucidValidationHelperFunctions.R")
# Load stacked dataset ----------------------------------------------------
load("AsianDiseaseStacked.rdata")
# OLS Regression Models -------------------------------------------------------
fit_AD_lucid <- lm(pfp~ mortality_frame, data=filter(ad_stacked, survey=="lucid"))
fit_AD_mturk <- lm(pfp~ mortality_frame, data=filter(ad_stacked, survey=="mturk"))
fit_AD_original <- lm(pfp~ mortality_frame, data=filter(ad_stacked, survey=="original"))
fit_test <- lm(pfp~ mortality_frame+ survey+ mortality_frame*survey, data=ad_stacked)
stargazer(fit_AD_lucid, fit_AD_mturk, fit_AD_original,
se = makerobustseslist(list(fit_AD_lucid, fit_AD_mturk, fit_AD_original)),
p = makerobustpslist(list(fit_AD_lucid, fit_AD_mturk, fit_AD_original)),
style = "apsr",
column.labels = c("Lucid", "MTurk", "Original"),
dep.var.labels = c("Preference for the Probabilistic Outcome"),
covariate.labels = c("Mortality Frame", "Intercept"),
title = "Asian Disease Replications",
label = "tab: KamSimas",
column.sep.width = "0pt",
omit.stat = c("f", "adj.rsq", "ser"),
notes= c("Robust standard errors are in parentheses.")
)
# Demographics Table
# Functions ---------------------------------------------------------------
install.packages("reshape2")
install.packages("scales")
install.packages("xtable")
install.packages("purrr")
install.packages("dplyr")
install.packages("matrixStats")
library(reshape2)
library(scales)
library(xtable)
library(purrr)
library(dplyr)
library(matrixStats)
source("LucidValidationHelperFunctions.R")
# Load Stacked Dataset ----------------------------------------------------
load("DemosTableStacked.rdata")
# Means and SEs -----------------------------------------------------------
means <-
demos_stacked %>%
filter(survey != "cps_income") %>%
select(-contains("income")) %>%
group_by(survey) %>%
summarize_each(funs(weighted.mean(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "mean")
ses <-
demos_stacked %>%
filter(survey != "cps_income") %>%
select(-contains("income")) %>%
group_by(survey) %>%
summarize_each(funs(weighted.se(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "se")
income_mean_df <-
demos_stacked %>%
group_by(survey) %>%
summarize(income_mean = dollar_format()(weighted.mean(income,w = weights, na.rm = TRUE)),
income_median = dollar_format()(matrixStats::weightedMedian(income,w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "mean")
income_ses_df <-
demos_stacked %>%
group_by(survey) %>%
summarize(income_mean = dollar_format()(weighted.se(income,w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "se")
income_df <- left_join(income_mean_df, income_ses_df) %>%
filter(survey != "cps")
income_df <- within(income_df, {
survey[survey == "cps_income"] <- "cps"
entry <- paste0(mean, " (", se, ")")
})
means_and_ses <- left_join(means, ses) %>%
filter(variable != "weights")
dont_multiply <- c("age", "education", "income_mean", "income_median")
means_and_ses <- within(means_and_ses,{
entry <- rep(NA, nrow(means_and_ses))
entry[variable %in% c("age", "education")] <-
paste0(format_num(mean[variable %in% c("age", "education")], digits = 2), " ",
add_parens(se[variable %in% c("age", "education")], digits = 2))
entry[!variable %in%dont_multiply] <-
paste0(format_num(100*mean[!variable %in%dont_multiply], digits = 2), " ",
add_parens(100*se[!variable %in%dont_multiply], digits = 2))
})
Ns <-
demos_stacked %>%
group_by(survey) %>%
summarize(n = n(),
n = comma_format()(n)) %>%
melt(id.var = "survey", value.name = "entry") %>%
filter(survey != "cps_income")
#150,799
df <- bind_rows(means_and_ses %>% select(survey, variable, entry),
income_df %>% select(survey, variable, entry),
Ns)
demo_table <- df %>% dcast(variable ~ survey, value.var = "entry") %>%
bind_rows(data.frame(variable = c("Race", "Region")))
demo_table <- within(demo_table,{
anes <- gsub(pattern = " \\(NA\\)", replacement = "", anes)
anes2012 <- gsub(pattern = " \\(NA\\)", replacement = "", anes2012)
anes_panel <- gsub(pattern = " \\(NA\\)", replacement = "", anes_panel)
cps <- gsub(pattern = " \\(NA\\)", replacement = "", cps)
lucid <- gsub(pattern = " \\(NA\\)", replacement = "", lucid)
mturk <- gsub(pattern = " \\(NA\\)", replacement = "", mturk)
mturk[mturk == "NaN (NaN)"] <- ""
variable <- factor(variable, levels = c("female","age","education","income_mean","income_median",
"Race", "race_white","race_black","race_hispanic","race_asian","race_native",
"Region", "region_northeast","region_midwest","region_south","region_west", "n"))
})
demo_table <-
demo_table[,c("variable", "lucid", "mturk", "anes_panel", "cps", "anes", "anes2012")] %>%
arrange(variable)
View(demo_table)
View(demo_table)
# Political Table
# Functions ---------------------------------------------------------------
install.packages("dplyr")
install.packages("reshape2")
install.packages("scales")
install.packages("xtable")
library(dplyr)
library(reshape2)
library(scales)
library(xtable)
source("LucidValidationHelperFunctions.R")
# Load Stacked Dataset ----------------------------------------------------
load("PoliticsTableStacked.rdata")
# Means and SEs -----------------------------------------------------------
means <-
politics_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.mean(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "mean")
ses <-
politics_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.se(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "se")
means_and_ses <- left_join(means, ses) %>%
filter(variable != "weights")
dont_multiply <- c("party7", "ideology", "interest")
means_and_ses <- within(means_and_ses,{
entry <- rep(NA, nrow(means_and_ses))
entry[variable %in% dont_multiply] <-
paste0(format_num(mean[variable %in% dont_multiply], digits = 2), " ",
add_parens(se[variable %in% dont_multiply], digits = 2))
entry[!variable %in%dont_multiply] <-
paste0(format_num(100*mean[!variable %in%dont_multiply], digits = 2), " ",
add_parens(100*se[!variable %in%dont_multiply], digits = 2))
})
Ns <-
politics_stacked %>%
group_by(survey) %>%
summarize(n = n(),
n = comma_format()(n)) %>%
melt(id.var = "survey", value.name = "entry")
df <- bind_rows(means_and_ses %>% select(survey, variable, entry),
Ns)
politics_table <- df %>% dcast(variable ~ survey, value.var = "entry") %>%
bind_rows(data.frame(variable = c("Opinions", "Behavior", "Traits")))
politics_table <- within(politics_table,{
anes <- gsub(pattern = " \\(NA\\)", replacement = "", anes)
anes <- gsub(pattern = "NA", replacement = "", anes)
anes2012 <- gsub(pattern = " \\(NA\\)", replacement = "", anes2012)
anes_panel <- gsub(pattern = " \\(NA\\)", replacement = "", anes_panel)
cps <- gsub(pattern = " \\(NA\\)", replacement = "", cps)
lucid <- gsub(pattern = " \\(NA\\)", replacement = "", lucid)
mturk <- gsub(pattern = " \\(NA\\)", replacement = "", mturk)
cps[cps == "NaN (NaN)"] <- ""
anes[anes == "NaN (NaN)"] <- ""
anes2012[anes2012 == "NaN (NaN)"] <- ""
variable <- factor(variable, levels = c("Behavior","register","vote",
"Traits","party7", "ideology", "interest", "knowl_score",
"Opinions", "seniors", "healthcare", "immigration", "gaymarriage", "taxrich", "taxpoor", "n"))
})
politics_table <-
politics_table[,c("variable", "lucid", "mturk", "anes_panel", "cps", "anes", "anes2012")] %>%
arrange(variable)
View(politics_table)
load("PsychTableStacked.rdata")
# Means and SEs -----------------------------------------------------------
means <-
psych_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.mean(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "mean")
ses <-
psych_stacked %>%
group_by(survey) %>%
summarize_each(funs(weighted.se(x = ., w = weights, na.rm = TRUE))) %>%
melt(id.vars = "survey", value.name = "se")
means <- within(means,{
mean[variable=="NFC" & survey=="mturk"] <- mean[variable=="NFC" & survey=="mturk_risk"]
mean[variable=="NTE" & survey=="mturk"] <- mean[variable=="NTE" & survey=="mturk_risk"]
mean[variable=="ramean" & survey=="mturk"] <- mean[variable=="ramean" & survey=="mturk_risk"]
})
ses <- within(ses,{
se[variable=="NFC" & survey=="mturk"] <- se[variable=="NFC" & survey=="mturk_risk"]
se[variable=="NTE" & survey=="mturk"] <- se[variable=="NTE" & survey=="mturk_risk"]
se[variable=="ramean" & survey=="mturk"] <- se[variable=="ramean" & survey=="mturk_risk"]
})
means_and_ses <- left_join(means, ses) %>%
filter(variable != "weights", survey!="mturk_risk")
means_and_ses <- within(means_and_ses,{
entry <- rep(NA, nrow(means_and_ses))
entry <-
paste0(format_num(mean, digits = 2), " ",
add_parens(se, digits = 2))
})
Ns <-
psych_stacked %>%
filter(survey!="mturk_risk")%>%
group_by(survey) %>%
summarize(n = n(),
n = comma_format()(n)) %>%
melt(id.var = "survey", value.name = "entry")
df <- bind_rows(means_and_ses %>% select(survey, variable, entry),
Ns)
psych_table <- df %>% dcast(variable ~ survey, value.var = "entry") %>%
bind_rows(data.frame(variable = "Big 5 Personality Index"))
psych_table <- within(psych_table,{
anes[anes == "NA (NA)"] <- ""
anes_panel[anes_panel == "NA (NA)"] <- ""
anes2012[anes2012 == "NA (NA)"] <- ""
anes2012[anes2012 == "NaN (NaN)"] <- ""
cces[cces == "NA (NA)"] <- ""
cces[cces == "NaN (NaN)"] <- ""
ccap[ccap == "NA (NA)"] <- ""
ccap[ccap == "NaN (NaN)"] <- ""
kam[kam == "NaN (NaN)"] <- ""
variable <- factor(variable, levels = c("Big 5 Personality Index","agreeableness","conscientiousness",
"emotionalstability","extraversion", "opennesstoexperiences", "ramean", "NFC",
"NTE", "n"))
})
psych_table <-
psych_table[,c("variable", "lucid", "mturk", "cces", "ccap", "anes_panel", "anes", "anes2012","kam" )] %>%
arrange(variable)
View(psych_table)
load("StandardizedDemos.rdata")
load("StandardizedExperiments.rdata")
demos_plot <-
ggplot(demos_standardized, aes(x = mean, y = Variable, group = Survey, color = Survey, shape = Survey)) +
geom_point(position = position_dodgev(height = .5)) +
geom_errorbarh(aes(xmin = li, xmax = ui),position = position_dodgev(height = .5), height = 0) +
theme_bw() +
facet_grid(facet~., scales = "free_y", space = "free_y") +
#scale_y_discrete(labels = varnames_demos) +
theme(axis.title = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
strip.background = element_blank()) +
coord_cartesian(xlim = c(-1, 1)) +
ggtitle("Standardized Means for Demographic Variables")
#Adjust variable to get the correct order
experiments_standardized$facet_f <- factor(experiments_standardized$facet, levels=c('Welfare', 'Asian Disease', 'Kam and Simas', 'Hiscox', 'Berinsky'))
experiments_plot <- ggplot(experiments_standardized, aes(x = coef, y = Variable, group = Survey, color = Survey, shape= Survey)) +
geom_point(position = position_dodgev(height = .5)) +
geom_errorbarh(aes(xmin = li, xmax = ui), position = position_dodgev(height = .5), height = 0) +
facet_grid(facet_f~., scales = "free_y", space = "free_y") +
theme_bw() +
theme(axis.title = element_blank(),
legend.position="bottom",
legend.title = element_blank(),
strip.background = element_blank()) +
coord_cartesian(xlim = c(-1.5, 1.5)) +
ggtitle("Standardized Treatment Effects For Experimental Replications")
experiments_plot
demos_plot
library(ggplot2)
library(coefplot)
load("standardizedExperimentsHeterogeneousTreatmentEffects.rdata")
standardizedExperiments1 <- filter(standardizedExperiments, facet=="Welfare"| facet=="Asian Disease" | facet=="Kam and Simas")
standardizedExperimentsHiscox <- filter(standardizedExperiments, facet=="Expert"| facet=="Positive frame"|facet=="Negative frame" | facet=="Both frames")
standardizedExperimentsBerinsky <- filter(standardizedExperiments, facet=="Rumor only"| facet=="Rumor + Nonpartisan correction"|facet=="Rumor + Republican correction" | facet=="Rumor + Democratic correction")
library(dplyr)
standardizedExperiments1 <- filter(standardizedExperiments, facet=="Welfare"| facet=="Asian Disease" | facet=="Kam and Simas")
standardizedExperimentsHiscox <- filter(standardizedExperiments, facet=="Expert"| facet=="Positive frame"|facet=="Negative frame" | facet=="Both frames")
standardizedExperimentsBerinsky <- filter(standardizedExperiments, facet=="Rumor only"| facet=="Rumor + Nonpartisan correction"|facet=="Rumor + Republican correction" | facet=="Rumor + Democratic correction")
load("standardizedExperimentsHeterogeneousEffects.rdata")
